package com.byd.sealmanage.config;

import com.alibaba.fastjson.JSONObject;
import com.byd.sealmanage.util.JsonUtil;
import lombok.Data;

import java.io.Serializable;

/**
 * Description: 通用返回结果
 *
 * @author gaochengyang
 * @since 2017-12-4
 */
@Data
public class CommonResultOutput<T> implements Serializable {

    //serialVersionUID 序列版本id
    private static final long serialVersionUID = -1212688121280486522L;
    /**
     * 状态：0000成功，9999失败
     */
    private String respCode;


    /**
     * 描述信息：respCode 为9999失败必填
     */
    private String respDesc;

    /**
     * 状态：0000成功，9999失败(前后端分离时使用)
     */
    private Integer status;

    /**
     * 描述信息：respCode 为9999失败必填（前后端分离时使用）
     */
    private String message;

    /**
     * 查询信息
     * @respCode 响应代码
     * @respDesc 响应描述
     */
    private T data;

    public CommonResultOutput(String respCode, String respDesc, T data) {
        this.respCode = respCode;
        this.respDesc = respDesc;
        this.data = data;
    }

    public CommonResultOutput(Integer status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public CommonResultOutput(Integer status, String message) {
        this.status = status;
        this.message = message;
    }

    public CommonResultOutput(String respCode, T data) {
        this.respCode = respCode;
        this.data = data;
    }

    public CommonResultOutput(String respCode, String respDesc) {
        this.respCode = respCode;
        this.respDesc = respDesc;
    }

    public CommonResultOutput(String respCode) {
        this.respCode = respCode;
    }
    public CommonResultOutput(){
    }


    public JSONObject commonOutput(String respCode, String respDesc, T data){
        CommonResultOutput commonResultOutput = new CommonResultOutput(respCode, respDesc, data);
        return JsonUtil.toJSONObject(commonResultOutput);
    }



    public JSONObject commonOutput(String respCode, String respDesc){
        CommonResultOutput commonResultOutput = new CommonResultOutput(respCode, respDesc);
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    public JSONObject commonOutput(){
        CommonResultOutput commonResultOutput = new CommonResultOutput( "0000", "调用成功");
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    public JSONObject commonOutput(T data){
        CommonResultOutput commonResultOutput = new CommonResultOutput( "0000", "调用成功",data);
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    public JSONObject commonSuccessOutput(String respDesc){
        CommonResultOutput commonResultOutput = new CommonResultOutput( "0000", respDesc);
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    public JSONObject commonSuccessOutput(String respDesc,T data){
        CommonResultOutput commonResultOutput = new CommonResultOutput( "0000", respDesc,data);
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    public JSONObject commonErrorOutput(String respDesc){
        CommonResultOutput commonResultOutput = new CommonResultOutput( "9999", respDesc);
        return JsonUtil.toJSONObject(commonResultOutput);
    }

    public JSONObject commonErrorOutput(String respDesc,T data){
        CommonResultOutput commonResultOutput = new CommonResultOutput( "9999", respDesc,data);
        return JsonUtil.toJSONObject(commonResultOutput);
    }
}
